package com.alfayun.fiscalriskanalysis.report;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
import javax.persistence.Table;

import com.alfayun.fiscalriskanalysis.reportspec.ReportSpec;

@Entity
@Table(name = "report")
public class Report {

	@Column(name = "report_id", updatable = false)
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Id
	private Integer id;
	public String serialNum; // 自定义编号
	@OneToOne
	@JoinColumn(name = "report_group_id")
	public ReportGroup reportGroup;
	@OneToOne
	@JoinColumn(name = "report_spec_id")
	public ReportSpec reportSpec;
	@OneToMany(mappedBy = "report", fetch = FetchType.LAZY)
	public List<Cell> cells;
	@Enumerated(EnumType.STRING) // 完成的状态：初始化，未完成，已完成
	public CompleteStatus completeStatus;

	public Integer getId() {
		return id;
	}

	public void setId(Integer id) {
		this.id = id;
	}

	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}

	public ReportGroup getReportGroup() {
		return reportGroup;
	}

	public void setReportGroup(ReportGroup reportGroup) {
		this.reportGroup = reportGroup;
	}

	public ReportSpec getReportSpec() {
		return reportSpec;
	}

	public void setReportSpec(ReportSpec reportSpec) {
		this.reportSpec = reportSpec;
	}

	public List<Cell> getCells() {
		return cells;
	}

	public void setCells(List<Cell> cells) {
		this.cells = cells;
	}

	public CompleteStatus getCompleteStatus() {
		return completeStatus;
	}

	public void setCompleteStatus(CompleteStatus completeStatus) {
		this.completeStatus = completeStatus;
	}

	public static Report newReport(ReportRepository repository, Report report) {
		report.id = 0;

		return repository.save(report);
	}

}
